<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>th:each循环</h1>
    <hr>
    <h2>遍历List</h2>
    <table border="1">
        <thead>
        <tr>
          <td>学号</td>
          <td>名字</td>
          <td>年龄</td>
        </tr>
        </thead>
        <tbody>
        <tr th:each="stu:${students}">
          <td th:text="${stu.id}"></td>
          <td th:text="${stu.name}"></td>
          <td th:text="${stu.age}"></td>
        </tr>
        </tbody>
    </table>
    <hr>

    <h2>遍历Map</h2>
    <p th:each="kv:${stuMap}">
        <!--    遍历Map，key无序    -->
        <span th:text="${kv.key}"></span>----<span th:text="${kv.value}"></span>
    </p>
    <hr>

    <h2>遍历list-map</h2>
    <ul th:each="lm:${listMap}">
        <li th:each="entry:${lm}">
            <span th:text="${entry.key}"></span>----><span th:text="${entry.value}"></span>
        </li>
    </ul>
    <hr>

    <h2>遍历数组[]</h2>
    <ul>
        <li th:each="name:${names}" th:text="${name}"></li>
    </ul>
    <hr>

    <h2>select组件</h2>
    <div>
        <select name="city" id="city">
            <option th:each="city:${cities}" th:value="${city.key}"
                    th:text="${city.value}" th:selected="${city.key} eq ${choice}"></option>
        </select>
    </div>
    <hr>

    <h2>使用状态变量来获取循环当中的信息</h2>
    <table>
        <thead>
        <tr>
            <td>信息</td>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>奇偶行</td>
        </tr>
        </thead>
        <tbody>
        <tr th:each="stu,loopStatus:${students}">
            <td th:text="${loopStatus.count} + '/' + ${loopStatus.size}"></td>
            <td th:text="${stu.id}"></td>
            <td th:text="${stu.name}"></td>
            <td th:text="${stu.age}"></td>
            <td th:text="${loopStatus.odd} ? '奇数行' : '偶数行'"></td>
        </tr>
        </tbody>
    </table>
</body>
</html>